JBoss Community Archive (Read Only)

SwitchYard 0.7

BPM Human Task API

SwitchYard provides an implementation-agnostic API is available which allows you to programmatically interact with Human Tasks.  The API provides mechanisms to:

The API is a very thin wrapper around jBPM, and doesn't cover everything you can do with jBPM.  As people require more functionality to be exposed, we will consider adding those hooks.

The purpose behind providing a SwitchYard-specific Task API is two-fold:

  1. Make it easy for web application developers to access and manage tasks in the BPM runtime.  The point here is that people are going to create their own web apps that interact with BPM tasks.

  2. Provide an abstraction over the implementation.  Using this API developers only have to worry about SwitchYard interfaces rather than depending upon another library. It also allows us to integrate with another BPM runtime in the future if we so choose (although the chances of that are slim for the foreseeable future).

For all examples below, please assume the following import:

import org.switchyard.component.bpm.task.*;

Starting and stopping a TaskServer

Starting and stopping a TaskServer can be done easily:

TaskServer server = TaskService.instance().newTaskServer();
server.setHost("localhost").setPort(9123).start();
// task clients can connect
server.stop();

Connecting and disconnecting a TaskClient

Connecting and disconnecting a TaskClient is just as easy:

TaskClient client = TaskService.instance().newTaskClient();
client.setHost("localhost").setPort(9123).connect();
// work with the client
client.disconnect();

Getting, claiming, starting and completing tasks

If you are familiar with jBPM 5, the method signatures below should seem somewhat familiar to you, as jBPM 5 is used under-the-hood. There are minor differences such as Long wrappers instead of long primitives for task ids, no need to specify a BlockingResponseHandler for client interaction, etc.

TaskClient client = // see above
String userId = "david";
List<String> groupIds = Arrays.asList(new String[]{"users"});
List<Task> tasks = client.getTasksAssignedAsPotentialOwner(userId, groupIds);
for (Task task : tasks) {
    if (TaskStatus.COMPLETED.equals(task.getStatus())) {
        continue;
    }
    Long taskId = task.getId();
    client.claim(taskId, userId, groupIds);
    client.start(taskId, userId);
    client.complete(taskId, userId, null);
}

Getting and setting task content

Application-specific objects are supported, and stores as name/value variables in a map within a TaskContent.  Because this data can be large, it is not pulled when initially querying for Tasks.  You have to make a separate call to the TaskClient to get the TaskContent.

TaskClient client = // see above
String userId = // see above
Task task = // see above
TaskContent content = client.getTaskContent(task.getTaskContentId());
Map<String, Object> data = content.getVariableMap();
MyAppObject mao = (MyAppObject)data.get("myAppVariable");
// use or mutate mao
client.complete(task.getId(), userId, content);

Examples

To see the Task API in action, please refer to the following quickstart demos in the SwitchYard distribution:

A video of the Help Desk Web App is available on YouTube.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-13 09:47:12 UTC, last content change 2013-01-16 18:45:13 UTC.